<!DOCTYPE html>
<html lang="en">

	<head>
		<meta charset="UTF-8">
		<meta name="viewport"
			content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />

		<title>末件检</title>
		<!-- 页面样式 -->
		<link rel="stylesheet" href="./assets/css/QMS/PageCss/DocumentsPage.css">
		<link rel="stylesheet" href="./assets/css/QMS/luckysheet/pluginsCss.css">
		<link rel="stylesheet" href="./assets/css/QMS/luckysheet/luckysheet.css">
		<link rel="stylesheet" href="./assets/css/QMS/luckysheet/plugins.css">
		<link rel="stylesheet" href="./assets/css/QMS/luckysheet/iconfont.css">
		<!-- <link rel="stylesheet" href="http://at.alicdn.com/t/c/font_4096975_i8f4jjygw.css"> -->
		<link rel="stylesheet" href="./assets/css/QMS/vant.min.css">
		<link rel="stylesheet" href="./assets/css/QMS/element.css">
		<script src="./assets/script/my-xmlhttprequest.js"></script>
		<script src="./assets/script/jquery.js"></script>
		<script src="./assets/script/vue.min.js"></script>
		<script src="./assets/script/vant.min.js"></script>
		<script src="./assets/script/element.js"></script>
		<script src="./assets/script/plugin.js"></script>
		<script src="./assets/script/umd.js"></script>
		<script src="./assets/js/base.js"></script>
		<script src="./assets/js/luckysheetConfig.js"></script>
		<script src="./assets/js/basicConfig.js"></script>

		<style>
		</style>
	</head>
	<body>
		<div id="app" v-cloak style="display: flex;justify-content: space-between;">
			<div style="position: relative;flex: 1;">
				<van-nav-bar title="末件检" right-text="按钮" left-arrow @click-left="onClickLeft">
					<div slot="right" class="NavbarRight">
						<van-button v-if="WorkInstructions.length" size="mini" type="primary" plain
							@click="OpenInstruction = true" style="margin-right: 8px;">作业指导书</van-button>

						<van-switch v-model="isProductPriority" size="18" style="margin-right: 5px;"></van-switch>
						{{isProductPriority?'横向':'纵向'}}

						<div style="margin-left: 6px;">
							<el-dropdown trigger="click">
								<div style="display: flex;align-items: center;">
									<van-icon name="apps-o" size="26" color="#333"></van-icon>
								</div>

								<el-dropdown-menu slot="dropdown">
									<el-dropdown-item>
										<div @click="OpenMainBox">
											<span>单据信息</span>
										</div>
									</el-dropdown-item>
									<el-dropdown-item>
										<div @click="OpenListPopup">
											<span>历史单据</span>
										</div>
									</el-dropdown-item>
									<el-dropdown-item>
										<div @click="OpenControl">
											<span>切换设备</span>
										</div>
									</el-dropdown-item>
								</el-dropdown-menu>
							</el-dropdown>
						</div>
					</div>
				</van-nav-bar>

				<!-- luckysheet容器 -->
				<div id="luckysheet"></div>

				<!-- 底部Bottom -->
				<div class="bottom">
					<div class="buttonBox" :style="{'z-index' : !showEditWindow ? '999' : '9'} ">
						<div class="BottomLeft" v-show="FinalInspectionID">
							<!-- 连接状态 -->
							<div class="StatusBox" v-if="DeviceInfo.ShowDeviceType" @click="SendMessage">
								<div class="deviceStatus"
									:style="{'background-color': deviceStatus ? '#17d56b':'#999'}">
								</div>
								<span class="StatusText"
									:style="{'color': deviceStatus ? '#17d56b':'#999'}">{{ deviceStatus ? '已连接' : '未连接' }}</span>
							</div>

							<div class="LeftTextBox">
								<div>
									<div>
										<span>样品数:</span>
										<span>{{originData.inspections.length}}</span>
									</div>

									<div>

										<span
											:style="{color: originData.mainData.Result == '1' ? '#17d56b':'#999'}">合格率:</span>
										<span
											:style="{color: originData.mainData.Result == '1' ? '#17d56b':'#999'}">{{QualifiedRate}}</span>
									</div>
								</div>
							</div>

							<div style="margin-left: 16px;font-size: 12px;"
								:style="{color: DeviceInfo.NeedDevice == DeviceInfo.DeviceModel ? '#3bc201' : '#999'}">
								<div>
									<span>所需设备：{{DeviceInfo.NeedDevice}}</span>
								</div>

								<!-- <div>
									<span>测量设备：{{DeviceInfo.DeviceModel}}</span>
								</div> -->
							</div>

						</div>

						<div class="btnBox">
							<van-button v-if="FinalInspectionID && ApproveBack('提交')" @click="SubmitBtn"
								type="info">提交</van-button>
						</div>
					</div>


					<div class="searchBox" ref="editKeyControl" :style="{'z-index' : showEditWindow ? '999' : '9'} "
						style="display: flex;align-items: center;justify-content: space-between;">
						<input :inputmode="InputFocus" type="text" class="IptStyle" id="autoInput" @blur="BlurSearch"
							@keydown.enter.prevent="submitKeyword"></input>

						<van-button class="confirmBtn" type="primary" size="small"
							@click="submitKeyword">确定</van-button>
					</div>
				</div>

				<!-- 可输入弹层，点击可输入的选框，弹起这个输入弹层 -->
				<!-- <van-popup v-model="showEditWindow" position="bottom" :overlay="false" style="height:50px">
				<van-search v-model="editKeyword" @blur="BlurSearch" background="#fff" left-icon="" show-action="true"
					ref="editKeyControl">
					<div slot="action" style="color:green;font-size:25px;" @click="submitKeyword">
						<van-icon name="checked" />
					</div>
				</van-search>
			</van-popup> -->

				<!-- 主表弹窗 -->
				<van-popup v-model="showMainBox" position="left" :lock-scroll="false" round
					:style="{ height: '100%',width:'50%' }">
					<div class="FormBox">
						<van-form>
							<van-field readonly v-model="originData.mainData.BillNO" label="单据编号"></van-field>
							<van-field readonly v-model="originData.mainData.BillDate" label="单据日期"></van-field>
							<van-field readonly v-model="originData.mainData.UserName" label="检验员"></van-field>
							<van-field readonly v-model="originData.mainData.ProductCode" label="品号"></van-field>
							<van-field readonly v-model="originData.mainData.ProductName" label="品名"></van-field>
							<van-field readonly v-model="originData.mainData.Fbatch" label="批次"></van-field>
							<van-field readonly v-model="originData.mainData.BJNum" label="来料数量"></van-field>
							<van-field readonly v-model="originData.mainData.CJQty" label="抽检数量"></van-field>
							<van-field readonly v-model="originData.mainData.HGNumber" label="合格数量"></van-field>
							<van-field readonly v-model="originData.mainData.BHGNumber" label="不合格数量"></van-field>
							<van-field readonly v-model="originData.mainData.Result1" label="检验结果" is-link
								@click="ChangeResultPopup = true"></van-field>
							<!-- <van-field readonly v-model="originData.mainData.Result" label="检验结果">
							<template #input>
								<span v-if="originData.mainData.Result == 1">合格</span>
								<span v-else>不合格</span>
							</template>
						</van-field> -->
							<van-field readonly v-model="originData.mainData.Approve" label="是否审核"></van-field>
							<van-field readonly v-model="originData.mainData.SFJY" label="是否检验"></van-field>
						</van-form>
					</div>

				</van-popup>

				<!-- 列表弹窗 -->
				<van-popup v-model="showListBox" round :close-on-click-overlay="false" :style="{ width:'90%' }">
					<!-- FinalInspectionID -->
					<van-cell title="末件检">
						<template #default>
							<van-icon v-if="FinalInspectionID" name="cross" size="20"
								@click="showListBox = false"></van-icon>

							<span v-else @click="onClickLeft">退出</span>
						</template>
					</van-cell>

					<!-- 列表 -->
					<div class="PopupTabsBox">

						<div class="RefreshIcon">
							<van-icon @click="RefreshTables" name="replay" size="20"></van-icon>
						</div>

						<el-tabs type="border-card" v-model="active">
							<el-tab-pane label="待检验">
								<div style="position: relative;">

									<el-table v-loading="NotTableLoading" :stripe="true" :data="NotListTableData"
										style="width: 100%" :height="MinNums" @cell-click="ChoiceTableCell">
										<el-table-column align="center" fixed type="index" width="50" :resizable="false"
											label="序号">
											<template slot-scope="scope">
												{{(NotPage.pageDocumentPage - 1) * NotPage.pageSize + scope.$index + 1}}
											</template>
										</el-table-column>
										<el-table-column align="center" prop="Result" label="判断结果" width="100">
											<template slot-scope="scope">
												<el-tag size="mini">{{FormatResultData(scope.row.ResultID)}}</el-tag>
												<!-- <el-tag size="mini">{{scope.row.Result}}</el-tag> -->
											</template>
										</el-table-column>
										<el-table-column align="center" prop="BillNO" label="单据编号" width="180">
										</el-table-column>
										<el-table-column align="center" prop="ProductName" label="产品名称" width="200">
										</el-table-column>
										<el-table-column align="center" prop="BillDate" label="单据日期" width="120">
										</el-table-column>
										<el-table-column align="center" prop="CJQty" label="抽检数量" width="80">
										</el-table-column>
										<el-table-column align="center" prop="HGNumber" label="合格数" width="80">
										</el-table-column>
										<el-table-column align="center" prop="BHGNumber" label="不合格数" width="100">
										</el-table-column>
									</el-table>

									<!-- 新增按钮 -->
									<van-icon size="40" color="#fff" @click="AddInspectionBtn"
										style="position: absolute;bottom: 15px;right: 4px;z-index: 999;background-color: #78d5ff;border-radius: 50%;"
										name="add-o"></van-icon>
								</div>
								<!-- 分页 -->
								<div class="PageBox">
									<div class="PageLeftBox">
										<span>总数：</span>
										<span>{{NotTotal}}</span>

										<span style="margin-left: 10px;">每页</span>
										<span>{{NotPage.pageSize}}</span>
										<span> 条</span>

									</div>

									<div class="PageRightBox">
										<van-pagination v-model="NotPage.pageIndex"
											:page-count="Math.ceil(NotTotal/NotPage.pageSize)" mode="simple"
											@change="ChangePageIndex(0)"></van-pagination>
									</div>

								</div>
							</el-tab-pane>
							<el-tab-pane label="已检验">
								<div style="position: relative;">

									<!-- 新增按钮 -->
									<van-icon size="40" color="#fff" @click="AddInspectionBtn"
										style="position: absolute;bottom: 15px;right: 4px;z-index: 999;background-color: #78d5ff;border-radius: 50%;opacity: .4;"
										name="add-o"></van-icon>

									<el-table v-loading="IsTableLoading" :stripe="true" :data="IsListTableData"
										:row-key="row => row.id" style="width: 100%" :height="MinNums"
										@cell-click="ChoiceTableCell">
										<el-table-column align="center" fixed type="index" :resizable="false" width="50"
											label="序号">
											<template slot-scope="scope">
												{{(IsPage.pageDocumentPage - 1) * IsPage.pageSize + scope.$index + 1}}
											</template>
										</el-table-column>
										<el-table-column align="center" prop="Approve" label="审核状态" width="100">
											<template slot-scope="scope">
												<el-tag size="mini" v-if="scope.row.Approve == '已审核'"
													type="success">已审核</el-tag>
												<el-tag size="mini" v-else type="info">未审核</el-tag>
											</template>
										</el-table-column>
										<el-table-column align="center" prop="Result" label="判断结果" width="100">
											<template slot-scope="scope">
												<el-tag size="mini">{{FormatResultData(scope.row.ResultID)}}</el-tag>
												<!-- <el-tag size="mini">{{scope.row.Result}}</el-tag> -->
											</template>
										</el-table-column>
										<el-table-column align="center" prop="BillNO" label="单据编号" width="180">
										</el-table-column>
										<el-table-column align="center" prop="ProductName" label="产品名称" width="200">
										</el-table-column>
										<el-table-column align="center" prop="BillDate" label="单据日期" width="120">
										</el-table-column>
										<el-table-column align="center" prop="BJNum" label="来料数量" width="80">
										</el-table-column>
										<el-table-column align="center" prop="CJQty" label="抽检数量" width="80">
										</el-table-column>
										<el-table-column align="center" prop="HGNumber" label="合格数" width="80">
										</el-table-column>
										<el-table-column align="center" prop="BHGNumber" label="不合格数" width="80">
										</el-table-column>
									</el-table>

								</div>
								<!-- 分页 -->
								<div class="PageBox">
									<div class="PageLeftBox">
										<span>总数：</span>
										<span>{{IsTotal}}</span>

										<span style="margin-left: 10px;">每页</span>
										<span>{{IsPage.pageSize}}</span>
										<span> 条</span>

									</div>

									<div class="PageRightBox">
										<van-pagination v-model="IsPage.pageIndex"
											:page-count="Math.ceil(IsTotal/IsPage.pageSize)" mode="simple"
											@change="ChangePageIndex(1)"></van-pagination>
									</div>

								</div>
							</el-tab-pane>
							<el-tab-pane label="已审核">
								<div style="position: relative;">

									<el-table v-loading="AuditTableLoading" :stripe="true" :data="AuditListTableData"
										:row-key="row => row.id" style="width: 100%" :height="MinNums"
										@cell-click="ChoiceTableCell">
										<el-table-column align="center" fixed type="index" :resizable="false" width="50"
											label="序号">
											<template slot-scope="scope">
												{{(AuditPage.pageDocumentPage - 1) * AuditPage.pageSize + scope.$index + 1}}
											</template>
										</el-table-column>
										<el-table-column align="center" prop="Approve" label="审核状态" width="100">
											<template slot-scope="scope">
												<el-tag size="mini" v-if="scope.row.Approve == '已审核'"
													type="success">已审核</el-tag>
												<el-tag size="mini" v-else type="info">未审核</el-tag>
											</template>
										</el-table-column>
										<el-table-column align="center" prop="Result" label="判断结果" width="100">
											<template slot-scope="scope">
												<el-tag size="mini">{{FormatResultData(scope.row.ResultID)}}</el-tag>
												<!-- <el-tag size="mini">{{scope.row.Result}}</el-tag> -->
											</template>
										</el-table-column>
										<el-table-column align="center" prop="BillNO" label="单据编号" width="180">
										</el-table-column>
										<el-table-column align="center" prop="ProductName" label="产品名称" width="200">
										</el-table-column>
										<el-table-column align="center" prop="BillDate" label="单据日期" width="120">
										</el-table-column>
										<el-table-column align="center" prop="BJNum" label="来料数量" width="80">
										</el-table-column>
										<el-table-column align="center" prop="CJQty" label="抽检数量" width="80">
										</el-table-column>
										<el-table-column align="center" prop="HGNumber" label="合格数" width="80">
										</el-table-column>
										<el-table-column align="center" prop="BHGNumber" label="不合格数" width="80">
										</el-table-column>
									</el-table>

								</div>
								<!-- 分页 -->
								<div class="PageBox">
									<div class="PageLeftBox">
										<span>总数：</span>
										<span>{{AuditTotal}}</span>

										<span style="margin-left: 10px;">每页</span>
										<span>{{AuditPage.pageSize}}</span>
										<span> 条</span>

									</div>

									<div class="PageRightBox">
										<van-pagination v-model="AuditPage.pageIndex"
											:page-count="Math.ceil(AuditTotal/AuditPage.pageSize)" mode="simple"
											@change="ChangePageIndex(2)"></van-pagination>
									</div>

								</div>
							</el-tab-pane>
						</el-tabs>

					</div>


					<!-- 点击历史单据列表 - 未检验 - 新增按钮 -->
					<!-- 添加z-index 避免弹层层级不够，出现样式问题 -->
					<van-popup v-model="AddInspection" :duration="0" style="z-index: 9999;"
						:style="{ width:'100%' ,height: '100%'}">
						<div class="AddPopup">

							<van-nav-bar left-arrow left-text="新增末件检" @click-left="CloseAddPopup">
								<template #right>
									<van-icon name="scan" size="24" @click="ToScan"></van-icon>
								</template>
							</van-nav-bar>

							<div class="AddPopupMainBox">
								<div class="FormBox">
									<van-field v-model="AddFormData.ProductName" label="品号" placeholder="请选择品号" readonly
										:error="Rule.ProductName" required @click="openBaseScreen('品号')"
										is-link>></van-field>

									<van-field v-model="AddFormData.ProcedureName" label="工序"
										:placeholder="FormPlaceHolder ? '请选择工序' : '请先选择品号'" readonly required
										:error="Rule.ProcedureName" @click="openBaseScreen('工序')" is-link></van-field>

									<van-field v-model="AddFormData.BJNum" label="来料数量" :readonly="!FormPlaceHolder"
										@blur="GetCJQty" :placeholder="FormPlaceHolder ? '请输入来料数量' : '请先选择品号'" required
										:error="Rule.BJNum" type="number"></van-field>

									<van-field v-model="AddFormData.Fbatch" label="批次" :readonly="!FormPlaceHolder"
										:placeholder="FormPlaceHolder ? '请输入批次' : '请先选择品号'" required
										:error="Rule.Fbatch"></van-field>

									<!-- 由品号自动带出 -->
									<van-field readonly v-model="AddFormData.ProductCode" label="品名"></van-field>
									<van-field readonly v-model="AddFormData.ProductSpec" label="规格"></van-field>
									<van-field readonly v-model="AddFormData.FMaterials" label="材质"></van-field>


									<!-- <van-field v-model="AddFormData.CJQty" label="抽检数量" :readonly="!FormPlaceHolder"
									:placeholder="FormPlaceHolder ? '请输入抽检数量' : '请先选择品号'" required :error="Rule.CJQty"
									type="number"></van-field> -->
									<van-field v-model="AddFormData.CJQty" label="抽检数量" readonly placeholder="请输入来料数量"
										type="number"></van-field>

								</div>
							</div>

							<div class="PopupBottomSubBtn">
								<van-button @click="AddSubmit" type="info" style="min-width: 100px;">新增</van-button>
							</div>

						</div>
					</van-popup>

				</van-popup>

				<!-- 主表修改检验结果弹层 -->
				<van-popup v-model="ChangeResultPopup" style="min-width: 280px;">
					<van-nav-bar left-text="检验结果"></van-nav-bar>

					<van-radio-group v-model="originData.mainData.Result">
						<van-cell-group>
							<van-cell v-for="item in ResuleOptions" :key="item.ID" :title="item.NAME" clickable
								@click="ChoiceMainResult(item)">
								<template #right-icon>
									<van-radio :name="String(item.ID)" />
								</template>
							</van-cell>
						</van-cell-group>
					</van-radio-group>
				</van-popup>

				<!-- 子表表格检验弹层 -->
				<van-popup v-model="showResult" @close="closeJYResult" style="min-width: 280px;">
					<van-nav-bar left-text="检验结果"></van-nav-bar>

					<van-radio-group v-model="isJYResult">
						<van-cell-group>
							<van-cell title="合格" clickable @click="showResult = false;isJYResult = '合格'">
								<template #right-icon>
									<van-radio name="合格" />
								</template>
							</van-cell>
							<van-cell title="不合格" clickable @click="showResult = false;isJYResult = '不合格'">
								<template #right-icon>
									<van-radio name="不合格" />
								</template>
							</van-cell>
						</van-cell-group>
					</van-radio-group>
				</van-popup>

				<!-- 筛选列表 -->
				<van-popup v-model="showBaseScreen" position="right" :style="{ height: '100%',width: '100%' }">
					<div style="display: flex;flex-direction: column;height: 100%;">
						<van-nav-bar class="head head-index" title="筛选" left-arrow
							@click-left="CloseBaseScreen"></van-nav-bar>

						<van-list style="flex: 1;overflow: auto;">
							<van-cell v-for="item in FilterList" :key="item.ProcedureID" @click="ChoiceListCell(item)">
								<template #title>
									<span>{{item.name}}</span>
									<!-- <span>{{item.ProcedureCode}}</span>
								<span style="margin: 0 6px;">|</span>
								<span>{{item.ProcedureName}}</span> -->
								</template>
							</van-cell>
						</van-list>

					</div>

				</van-popup>

				<!-- 作业指导书列表 -->
				<van-popup v-model="OpenInstruction" round :close-on-click-overlay="false"
					:style="{ height: '80%',width: '90%' }">
					<div style="display: flex;flex-direction: column;height: 100%;">
						<van-cell title="作业指导书">
							<template #default>
								<van-icon name="cross" size="20" @click="OpenInstruction = false"></van-icon>
							</template>
						</van-cell>
						<!-- SendMessage('showPopup') -->
						<el-table :data="WorkInstructions" border style="width: 100%" :height="MinNums"
							@cell-click="ChoiceInstruction">
							<el-table-column align="center" prop="FileName" label="文件">
							</el-table-column>
							<el-table-column align="center" prop="ProductName" label="产品名称">
							</el-table-column>
							<el-table-column align="center" prop="format" label="文件格式">
							</el-table-column>
						</el-table>
					</div>
				</van-popup>

				<!-- 指定设备开启的对应展示弹层 -->
				<!-- 接收报告数据 -->
				<!-- showTableData_Report_popup -->
				<van-popup v-model="showTableData_Report_popup" round :close-on-click-overlay="false">
					<div class="f-dc rowDevice" style="width: 300px;height: 60vh;">
						<van-nav-bar left-text="检验报告">
							<template #right>
								<van-icon name="cross" size="18" @click="showTableData_Report_popup = false;" />
							</template>
						</van-nav-bar>

						<div class="flex-auto">
							<van-radio-group v-model="tableData_Report_radio" @change="tableData_Report_change">
								<van-cell-group>
									<van-cell v-for="(item,index) in tableData_Report" :title="'报告 ' + (index + 1)"
										clickable @click="tableData_Report_radio = index">
										<template #right-icon>
											<van-radio :name="index" />
										</template>
									</van-cell>
								</van-cell-group>
							</van-radio-group>

						</div>

						<div class="x-ec" style="padding: 10px;">
							<van-button style="margin-left: 6px;width: 80px;" size="small" type="info" plain
								@click="ViewReportInfoBtn">预览</van-button>
							<van-button style="margin-left: 6px;width: 80px;" size="small" type="info"
								@click="SubmitViewReportInfoBtn">确定</van-button>
						</div>

					</div>
				</van-popup>

				<!-- 光谱 -->
				<van-popup v-model="showRowInfoByDevice" :close-on-click-overlay="false">
					<div class="f-dc rowDevice">
						<van-nav-bar left-text="检验报告">
							<template #right>
								<van-icon name="cross" size="18" @click="showRowInfoByDevice = false;" />
							</template>
						</van-nav-bar>

						<div style="padding: 10px 10px 0;">
							<el-form ref="rowDeviceForm" label-width="80px">
								<el-form-item label="检验结果">

									<el-radio-group v-model="rowDeviceForm.result">
										<el-radio :label="1">合格</el-radio>
										<el-radio :label="0">不合格</el-radio>
									</el-radio-group>
								</el-form-item>
							</el-form>
						</div>

						<div class="flex-auto">
							<van-row class="rowDeviceBox">
								<van-col span="8" v-for="key in Object.keys(popup_ReportData)">
									<el-input v-model="popup_ReportData[key]" readonly>
										<template slot="prepend">{{key}}</template>
									</el-input>
								</van-col>
							</van-row>
						</div>

						<div style="height: 100%;width: 100%;overflow: hidden;"
							v-if="ChoiceCellData.hasOwnProperty('Benchmark') && ChoiceCellData.Benchmark.includes('三坐标')">
							<iframe v-if="openPopupIframe" src="./ReportPage/Report_SZB.html" class="report_iframe1"
								style="height: 100%;width: 100%;" frameborder="0"></iframe>
						</div>

						<div style="height: 100%;width: 100%;overflow: hidden;"
							v-if="ChoiceCellData.hasOwnProperty('Benchmark') && ChoiceCellData.Benchmark.includes('影像测量仪')">
							<iframe v-if="openPopupIframe" src="./ReportPage/Report_YXY.html" class="report_iframe1"
								style="height: 100%;width: 100%;" frameborder="0"></iframe>
						</div>

						<div class="x-ec btnBox" style="padding: 10px 15px;">

							<van-button type="info" class="confirmBtn" size="small"
								@click="submitRowInfo">确认</van-button>
						</div>
					</div>
				</van-popup>

			</div>


			<div v-if="IsShowWorkPage" style="border: 1px solid #333;min-width: 40vw;">
				<!-- :src="`${APP.IPAgreement() + APP.serverIP()}/assets/preOffice/preview.html?src=https://emoji.raingad.com/file/1.pdf`" -->
				<iframe style="width: 100%;height: 100%;" src="./Instruction.html" frameborder="0"></iframe>
			</div>

		</div>
	</body>
	<!-- 调用 uniapp webview 的 api ，记得需要写在 body 标签下面 -->
	<script src="./assets/script/uni.webview.1.5.4.js"></script>

	<script>
		// 开启 h5 页面 与 vue主页面的 信息交互
		document.addEventListener('UniAppJSBridgeReady', function() {
			// uni.postMessage({
			// 	data: {
			// 		action: 'message'
			// 	}
			// });
		})
		var vm = new Vue({
			el: '#app',
			data: {
				ShowMyFilter: false, // 是否展示筛选弹层
				filterData: {
					Approve: [{
						text: '未审核',
						value: 0
					}, {
						text: '已审核',
						value: 1
					}]
				},
				GetFilter: {
					Approve: '',
				},
				Permissions: { // 权限
					HasChangeResult: false, // 是否有主表修改结果的权限
				},
				InputFocus: 'none', // 输入框是否可弹起键盘
				DeviceInfo: {
					Communication: '', // 协议类型
					DeviceModel: '', // 选中的设备名称  用处：点击单元格，使用测量工具测量，若与之不一致，则无法测量
					ShowDeviceType: false, // 是否显示左下角设备连接状态，
					NeedDevice: '', // 点击单元格，所对应需要的测量设备
				},
				UserInfo: {}, // 用户信息
				deviceStatus: false, // 记录设备蓝牙连接状态
				active: 0, // 标签页
				NotPage: {
					pageIndex: 1,
					pageSize: 5,
					pageDocumentPage: 1,
				},
				PageIndexTimer: null, // 用于切换分页时的防抖
				NotListTableData: [], // 未报检列表数据
				NotTotal: null, // 未检验总数
				NotTableLoading: false, // 未检验表格弹窗loading
				IsPage: {
					pageIndex: 1,
					pageSize: 5,
					pageDocumentPage: 1,
				},
				IsListTableData: [], // 已检验
				IsTotal: null, // 已检验总数
				IsTableLoading: false, // 已检验表格弹窗loading
				AuditPage: {
					pageIndex: 1,
					pageSize: 5,
					pageDocumentPage: 1,
				},
				AuditListTableData: [], // 已审核
				AuditTotal: null, // 已审核总数
				AuditTableLoading: false, // 已审核表格弹窗loading
				FinalInspectionID: null, // 进货检验单主键id
				showListBox: true, // 展示单据列表
				AddInspection: false, // 单据列表中的新增弹窗
				FormPlaceHolder: false, // 新增弹层表单——品号是否存在
				AddFormData: { // 新增弹窗表单内容
					ProcedureID: '', // 工序
					ProcedureCode: '',
					ProcedureName: '',

					ProductID: '', // 品号
					ProductName: '',
					ProductSpec: '', // 规格
					FMaterials: '', // 材质
					Fbatch: '', // 批次
					BJNum: '', // 来料数量
					CJQty: '', // 抽检数量
				},
				Rule: { // 新增弹窗表单验证
					ProductName: false, // 品号
					ProcedureName: false, // 工序
					BJNum: false, // 来料数量
					Fbatch: false, // 批次
				},

				showTableData_Report_popup: false, // 接收报告数据弹层
				tableData_Report_radio: 0, // 默认选中报告
				tableData_Report: [], // 接收报告数据的数组
				showRowInfoByDevice: false, // 展示子表为报告类型时，展示的弹层
				popup_ReportData: {}, // 报告类型弹层数据
				rowDeviceForm: { // 报告检验结果
					result: 1
				},
				report_frame_height: 0, // 报告弹层iframe高度
				openPopupIframe: false,

				ChoiceCellData: {}, // 单元格选中数据（允许修改的数据信息）

				showBaseScreen: false, // 显示筛选弹层
				SelectName: '', // 记录新增表单点击项
				FilterList: [], // 筛选弹层列表
				MinNums: 250, // 单据列表表格高度
				showMainBox: false, // 是否显示主表内容弹层
				showResult: false, // 是否显示子表表格检验弹层
				isJYResult: 1, // 子表弹窗选中值（其实应该是 合格、不合格）
				immersed: 0, // 安全高度 
				IsWhere: 'A1', // 选中的单元格位置，默认选中 A1
				showEditWindow: false, // 是否显示输入框（只有双击可编辑的单元格的时候，才会为 true）
				editKeyword: '', // 输入框值 
				editRange: [], // 单元格选中信息
				headerLevel: 0, // 标题头递归层级
				isProductPriority: true, // 横向、纵向
				RejectionNum: 0, // 根据来料数量返回的拒收数量（可以是不合格的数量）
				ChangeResultPopup: false, // 修改检验结果弹层
				ChangeResult: '', // 检验结果弹层选中
				ResuleOptions: [], // 主表检验结果列表
				originData: {
					mainData: {}, // 主表数据
					inspections: [], // 子表数据
					FQCDetail: [] // 子子表数据
				},
				QualifiedRate: null, // 合格率
				editCells: [],
				OpenInstruction: false, // 是否显示作业指导书弹窗
				throttledOpen: false, // 打开作业指导书的节流记录，避免重复点击
				WorkInstructions: [], // 作业指导书
				RemarkIndex: { // 备注的索引位置
					r: null,
					c: null
				},
				IsShowWorkPage: false, // 是否展示作业指导书内容
				FilePath: null, // 作业指导书显示内容
				BtnApprove: [], // 按钮权限数据
			},
			created: function() {
				var that = this;
				let immersed = 0;
				//获取当前手机状态栏高度
				if (window.localStorage.getItem('safeAreaInsetTop')) {
					immersed = window.localStorage.getItem('safeAreaInsetTop');
				} else {
					let ms = (/Html5Plus\/.+\s\(.*(Immersed\/(\d+\.?\d*).*)\)/gi).exec(navigator
						.userAgent);
					if (ms && ms.length >= 3) { // 当前环境为沉浸式状态栏模式
						immersed = parseFloat(ms[2]); // 获取状态栏的高度
					}
					window.localStorage.setItem('safeAreaInsetTop', immersed)

				}
				this.immersed = immersed;


				// 初始化时，取屏幕宽高的最小值，用于表格列表高度
				const MinNums = Math.min(screen.height, screen.width)
				let SetTableNums = 250

				if (MinNums < 500) {
					SetTableNums = 200
				} else {
					SetTableNums = 250
				}
				this.MinNums = SetTableNums

				// 开启表格弹窗加载,初始化的时候必须开启加载，不然会因为定时器，出现片刻空状态字样
				this.NotTableLoading = true
				this.IsTableLoading = true
				this.AuditTableLoading = true
				setTimeout(() => {
					$('#app').css({
						'padding-top': immersed + 'px'
					})
				}, 50)
			},
			computed: {},
			watch: {
				'AddFormData.BJNum'(val) { // 监听新增弹层表单中的 来料数量是否有值
					var that = this

					that.Rule.BJNum = !val ? true : false
				},
				'AddFormData.Fbatch'(val) { // 监听新增弹层表单中的批次是否有值
					var that = this

					that.Rule.Fbatch = !val ? true : false
				},
				'AddFormData.ProcedureName'(val) { // 监听新增弹层表单中的工序是否有值
					var that = this

					that.Rule.ProcedureName = !val ? true : false
				},
				'AddFormData.ProductName': { // 监听新增弹层表单中的品号是否存在
					handler(val) {
						var that = this
						that.Rule.ProductName = !val ? true : false
						that.FormPlaceHolder = !val ? false : true
					},
				},
				QualifiedRate: {
					handler(val) { // 监听合格率，给主表赋值
						var that = this

						if (val == '100%') {
							// that.originData.mainData.Result1 = '合格'
							that.originData.mainData.Result1 = that.FormatResultData(1);
							that.originData.mainData.Result = '1'

						} else {

							let TrueLength = that.originData.inspections.filter(item => {
								return item.result != '1'
							}).length
							// console.log(that.RejectionNum)

							if (TrueLength >= that.RejectionNum) {
								that.originData.mainData.Result1 = that.FormatResultData(0);
								// that.originData.mainData.Result1 = '不合格'
								that.originData.mainData.Result = '0'
							} else {
								// that.originData.mainData.Result1 = '合格'
								that.originData.mainData.Result1 = that.FormatResultData(1);
								that.originData.mainData.Result = '1'
							}

						}
					},
					deep: true,
					// immediate: true
				}

			},
			mounted() {
				var that = this;
				// 点击屏幕任何地方，都触发
				$(document).on('click', function(e) {

					if (!that.showEditWindow && !that.AddInspection) {
						const input = document.getElementById('autoInput');
						input.focus(); // 初始聚焦

						input.addEventListener('blur', () => {
							setTimeout(() => input.focus(), 0); // 失焦后立即重新聚焦
						});

					}
				});

				// 监听来自iframe的消息
				window.addEventListener('message', function(event) {

					// 如果iframe请求了父页面的数据，可以在这里回复
					if (event.data === 'getHeight') {
						let obj = {
							name: "getHeight",
							value: vm.report_frame_height
						}
						event.source.postMessage(obj, "*");
					} else if (event.data === 'getReportRadio') { // 选中报告索引
						let obj = {
							name: "getReportRadio",
							value: vm.tableData_Report_radio
						}
						event.source.postMessage(obj, "*");

					}
				});

				// 在组件挂载后初始化Luckysheet
				setTimeout(() => {
					$('#luckysheet').css({
						'height': `calc( 100vh - ${that.immersed}px - ${$('.van-nav-bar').height()}px - ${$('.bottom').height()}px - 4px ) `
					});
				}, 300);
			},
			methods: {
				// webview 初始化
				page_initConfig(configInfo) {
					let that = this;

					const {
						GetDocumentInfo,
						GetUserInfo,
						SetServiceIP,
						GetBtnPermission,
					} = JSON.parse(configInfo);;

					console.log(GetUserInfo);



					// 存储用户信息
					this.UserInfo = GetUserInfo;

					if (this.UserInfo.Business_Code == '025') {
						this.ShowAddBtn = false;
					} else {
						this.ShowAddBtn = true;
					}
					APP.getUserInfo(GetUserInfo);

					// 存储 IP 信息
					APP.serverIP(SetServiceIP.serverIP);
					APP.IPAgreement(SetServiceIP.IPAgreement);

					setTimeout(() => {
						// 列表数据查询
						that.getListFun(0)
						that.getListFun(1)
						that.getListFun(2)

						// 获取一下主表检验结果列表
						that.GetMainResultList()

						// 获取是否有权限显示
						// that.GetPermissions()
					}, 300)


					this.BtnApprove = GetBtnPermission


					// 快速打开单据
					if (GetDocumentInfo) {
						this.GetDocumentInfo(GetDocumentInfo)
					}


				},




				// 不可覆盖
				ToScan() { // 扫一扫
					uni.postMessage({
						data: {
							action: 'ToScan'
						}
					});
				},
				GetToScanInfo(data) { // 获取扫码结果

					var NewData = data.result
					var TheIndex = NewData.indexOf('|')
					if (TheIndex != -1) {
						NewData = NewData.slice(TheIndex + 1)
					}

					var obj = {
						QrCode: NewData
					}

					APP.jqueryAjax('selectCPXXByERWM', obj, function(res) {
						if (res.status == 200) {

							vm.AddFormData = Object.assign(vm.AddFormData, res.data.ds[0]);

							vm.GetCJQty()
						}
					}, function(err) {
						console.log(JSON.stringify(err))
					})
				},
				// openBaseScreen(data) {

				// 	if (data == '工序' && !vm.AddFormData.ProductName) {
				// 		return vant.Toast.fail('请选择品号')
				// 	}

				// 	vm.SelectName = data
				// 	vm.showBaseScreen = true
				// 	setTimeout(() => {
				// 		$('.head-index').css({
				// 			'padding-top': vm.immersed + 'px'
				// 		})
				// 	}, 300)
				// 	let url = {}
				// 	let obj = {}

				// 	if (data == '工序') {
				// 		url = 'selectGXXXByCPID'
				// 		obj = {
				// 			ProductID: vm.AddFormData.ProductID,
				// 			InspectionID: 5,
				// 		}
				// 	} else if (data == '品号') {
				// 		url = 'Droplist_CPProduct'
				// 		obj = {
				// 			InspectionID: 5
				// 		}

				// 	}

				// 	vm.GetInterfaceData(url, obj, data)
				// },
				GetBaseCreenBack(val) { // 接收下拉筛选返回的值
					let that = this;
					// 判断是否为空对象
					if (!APP.isEmpty(val)) {
						let data = JSON.parse(val);

						if (data.titleName == '品号') {
							APP.jqueryAjax('APP_GetCPXXByCPID', {
								ProductID: data.data.ProductID
							}, function(res) {
								if (res.status == 200) {
									vm.AddFormData = Object.assign(vm.AddFormData, res.data.ds[0]);
								}
							})
						} else if (data.titleName == '工序') {
							that.AddFormData = Object.assign(that.AddFormData, data.data);

						}
					}
				},
				openBaseScreen(data) { // 前往筛选，将参数带上
					let that = this;

					if (data == '工序' && !vm.AddFormData.ProductName) {
						return vant.Toast.fail('请选择品号')
					}

					let obj = null;
					let path = '';

					if (data == '工序') {
						path = 'selectGXXXByCPID';

						obj = {
							allowClear: false, // 清除按钮
							cmd: path, // 接口名
							titleName: data,
							multiple: false, // 是否开启多选
							serverSearch: { // 查询项
								format: { // 数据映射
									displayValue: "ProcedureName", // 显示值
									hiddenValue: "ProcedureID", // 隐藏值
								},
								isPaging: false, //是否分页
								choiceData: vm.AddFormData.ProcedureID, // 选中数据
								choiceDataKey: "ProcedureID", // 选中数据的key
							},
							param: { // 传递参数
								ProductID: vm.AddFormData.ProductID,
								InspectionID: 5,
							}
						}
					} else if (data == '品号') {
						path = 'Droplist_CPProduct';

						obj = {
							allowClear: false, // 清除按钮
							cmd: path, // 接口名
							titleName: data,
							multiple: false, // 是否开启多选
							serverSearch: { // 查询项
								format: { // 数据映射
									displayValue: "ProductName", // 显示值
									hiddenValue: "ProductID", // 隐藏值
									pageIndex: "pageIndex", // 分页状态页码字段
									pageSize: "pageSize", // 分页状态每页数量字段
								},
								isPaging: true, //是否分页
								searchKey: 'ProductName', //搜索关键词，应包含在param中
								choiceData: vm.AddFormData.ProductID, // 选中数据
								choiceDataKey: "ProductID", // 选中数据的key
							},
							param: { // 传递参数
								ProductName: '',
								InspectionID: 5,
								pageIndex: 1,
								pageSize: 30,
							}
						}
					}



					that.SendMessage('baseScreen', obj)
				},
				GetInterfaceData(cmd, pram, name) {
					APP.jqueryAjax(cmd, pram, function(res) {
						// console.log(JSON.stringify(res))
						if (res.status == 200) {
							res.data.ds.forEach(item => {
								if (name == '工序') {
									item.name = item['ProcedureName']
									// item.name = item['ProcedureCode'] + '|' + item['ProcedureName']
								} else if (name == '品号') {
									item.name = item['ProductName']
								}
							})
							vm.FilterList = res.data.ds
						}
					})
				},
				AddSubmit() { // 新增
					if (!vm.AddFormData.ProcedureID || !vm.AddFormData.ProductID || !vm.AddFormData
						.Fbatch || !vm.AddFormData.BJNum) {

						if (!vm.AddFormData.ProductID) { // 如果 品号 和 工序 没有值
							vm.Rule.ProductName = true
							vm.Rule.ProcedureName = true
						}

						if (!vm.AddFormData.ProcedureID) { // 如果 品号 和 工序 没有值
							vm.Rule.ProcedureName = true
						}

						if (!vm.AddFormData.BJNum) { // 如果抽检数量没有值
							vm.Rule.BJNum = true
						}
						if (!vm.AddFormData.Fbatch) { // 如果批次没有值
							vm.Rule.Fbatch = true
						}

						return vant.Toast.fail('请完善表单')
					}

					/**新增
					 * Fbatch 			批次
					 * BJNum 			来料数量
					 * CJQty 			抽检数量
					 * ProcedureID 		产品ID
					 * ProductName 		产品名称
					 * ProductSpec 		规格
					 * FMaterials 		材质
					 * EmplID 			检验员
					 */
					let pram = {
						Fbatch: vm.AddFormData.Fbatch,
						BJNum: vm.AddFormData.BJNum,
						CJQty: vm.AddFormData.CJQty,
						ProcedureID: vm.AddFormData.ProcedureID,
						ProductID: vm.AddFormData.ProductID,
						ProductName: vm.AddFormData.ProductName,
						ProductSpec: vm.AddFormData.ProductSpec,
						FMaterials: vm.AddFormData.FMaterials,
						EmplID: vm.UserInfo.UserID,
						FPMCID: vm.AddFormData.FPMCID,
						FPMCDeID: vm.AddFormData.FPMCDeID,
					}
					// return console.log(JSON.stringify(pram))
					APP.jqueryAjax('selectMJJXXByCPGX', pram, function(res) {
						console.log(JSON.stringify(res))
						if (res.status == 200) {
							if (res.data.ds[0].status == 200) {
								vant.Toast(res.data.ds[0].msg)

								vm.getListFun(0)
								// 关闭并清空
								vm.CloseAddPopup()

								vm.ChoiceTableCell(res.data.ds[0])
							} else {
								vant.Toast(res.data.ds[0].msg)
							}

						} else {
							vant.Toast('新增失败，请重试！')
						}
					})
				},
				getListFun(data) { // 获取检验列表数据
					var that = this

					/*
					 * data  		接收是否检验： 0 - 未检验、1 - 已检验
					 * pageIndex	需要注意，从 1 开始
					 * Approve		审核条件  '' - 全部 ， 0 - 未审核，1 - 已审核
					 */
					// 声明两个变量，接收 分页的 属性名称
					let AttributePageName = "";
					let Approve = 0;
					let SFJY = 1;
					if (data == 1) {
						Approve = 0;
						AttributePageName = 'IsPage';
						vm.IsTableLoading = true;
					} else if (data == 0) {
						AttributePageName = 'NotPage';
						vm.NotTableLoading = true;
						SFJY = 0
					} else if (data == 2) {
						AttributePageName = 'AuditPage';
						vm.AuditTableLoading = true;
						Approve = 1;
					};
					let obj = {
						pageIndex: vm[AttributePageName].pageIndex,
						pageSize: vm[AttributePageName].pageSize,
						SFJY: SFJY,
						Approve: Approve
					}
					// console.log(JSON.stringify(obj))

					APP.jqueryAjax('APP_MJJLIST', obj, function(res) {
						// 声明两个变量，接收存储的 数组名称
						let AttributeListName = ''
						let TotalName = ''
						if (data == 1) {
							AttributeListName = 'IsListTableData'
							TotalName = 'IsTotal'

						} else if (data == 0) {
							AttributeListName = 'NotListTableData'
							TotalName = 'NotTotal'
						} else if (data == 2) {
							AttributeListName = 'AuditListTableData'
							TotalName = 'AuditTotal'
						}
						// console.log(JSON.stringify(res.data.ds))
						// 给表格赋值
						vm[AttributeListName] = res.data.ds;

						// 给对应的分页总数 赋值
						vm[TotalName] = (res.data.ds1.length && res.data.ds1[0].Total) ? res.data
							.ds1[0]
							.Total : 0;
						vm[AttributePageName].pageDocumentPage = vm[AttributePageName].pageIndex

						setTimeout(() => {
							if (data == 1) {
								vm.IsTableLoading = false

							} else if (data == 0) {
								vm.NotTableLoading = false
							} else if (data == 2) {
								vm.AuditTableLoading = false
							}
						}, 1000)

					})
				},
				ChoiceTableCell(row, column, cell, event) { // 单机表格行
					// 记录点击的表格行ID，同时用于弹窗表格右上方按钮，有值时显示 关闭弹窗，无时显示 退出
					vm.FinalInspectionID = row.FinalInspectionID
					let obj = {
						FinalInspectionID: row.FinalInspectionID
					}
					// 获取 APP进货检验单明细
					APP.jqueryAjax('APP_MJJMX', obj, function(res) {
						// 计算合格率
						vm.QualifiedRate = BackRercentageData(res.data.ds1, 'FResult', 1)

						Promise.resolve().then(() => {
							// 给主表赋值
							let mainData = res.data.ds[0];
							// 因为主表的结果下拉，需要字符串格式
							if (mainData.Result != null && mainData.Result != undefined) {
								mainData.Result = String(mainData.Result)
							}
							vm.originData.mainData = mainData;


							let basicConfigInfo = basicConfig.initConfig(res.data,
								'FinalInspectionDeID',
								'FinalInspectionDeDeID');
							console.log(JSON.stringify(basicConfigInfo))

							Object.assign(vm.originData, {
								inspections: basicConfigInfo.inspections,
								FQCDetail: basicConfigInfo.FQCDetail,
							});

							// console.log(JSON.stringify(vm.originData))
							// 对获取数据后 重构的对象数据，进一步重构
							vm.getPageData();
							// 关闭Tabs表格弹窗
							vm.showListBox = false;
							vm.GetFileType(vm.originData.mainData.ProductID); // 根据产品ID，获取作业指导书数据
						})
					})
				},
				GetAllowErrors(data) { // 获取根据来料数量，允许的不合格数范围
					/**
					 * FinalInspectionID  	主键ID
					 * BJNum	来料数量
					 */
					APP.jqueryAjax('APP_selectMJJCJSL', {
						FinalInspectionID: data.FinalInspectionID,
						BJNum: data.BJNum
					}, function(res) {
						if (res.data.ds[0].status == 200) {
							vm.RejectionNum = res.data.ds[0].RejectionNum
						} else {
							res.data.ds[0].msg
						}
					})
				},
				SubmitBtn() { // 提交按钮
					vant.Toast.loading({
						message: '加载中...',
						forbidClick: true,
					});

					var obj = {
						json: JSON.stringify(vm.originData)
					}
					APP.jqueryAjax('updateMJins', obj, (res) => {
						// console.log(JSON.stringify(res.status))
						if (res.status == 200) {

							vant.Toast.clear();

							setTimeout(() => {
								vant.Toast.success('提交成功！')
								vm.showListBox = true
								vm.RefreshTables()
							}, 500)
						}
					}, (err) => {

					}, '1')
					// } else {
					// 	vant.Toast('请选择检验结果！')
					// 	vm.showMainBox = true
					// }
				},
				FormatResultData(ID) { // 根据结果ID，返回对应的结果名称
					let HasResult = vm.ResuleOptions.find(item => item.ID == ID)

					if (APP.isEmpty(HasResult)) {
						return ''
					} else {
						return HasResult['NAME']
					}
				},
				GetMainResultList() { // 获取主表检验结果列表
					APP.jqueryAjax('APP_JHJYD_PDJG', {}, function(res) {
						// console.log(JSON.stringify(res))
						if (res) {
							if (res.status == 200) {
								vm.ResuleOptions = res.data.ds
							}

						}
					})
				},


				// 通用，可覆盖
				GetFileType(ID) { // 根据产品ID，获取作业指导书数据
					var that = this;
					that.WorkInstructions = []
					try {
						APP.jqueryAjax('selectSIPByProductID', {
							ProductID: ID
						}, function(res) {
							if (res.status == 200) {
								if (res.data.ds && res.data.ds.length) {
									res.data.ds.map(item => {
										item.format = that.getExtensionAfterLastDot(item.FilePath)
									})
									that.WorkInstructions = res.data.ds
								}
								// console.log(JSON.stringify(that.WorkInstructions))

							}
						})
					} catch (e) {
						//TODO handle the exception
					}
				},
				getExtensionAfterLastDot(str) { // 根据传入地址，返回文件流格式类型：pdf excel
					const lastDotIndex = str.lastIndexOf('.');
					if (lastDotIndex !== -1) {
						return str.substring(lastDotIndex + 1);
					} else {
						return '';
					}
				},
				ChoiceInstruction(row) { // 选中作业指导书
					var that = this;
					// console.log(JSON.stringify(that.originData));
					if (!row.FilePath) {
						return vant.Toast.fail("无法找到链接");
					}
					this.FilePath = row.FilePath;
					this.OpenInstruction = false;
					// this.IsShowWorkPage = true;

					// vm.getPageData();
					// return
					// console.log(JSON.stringify(row.FilePath));

					if (!that.throttledOpen) {
						that.throttledOpen = true;
						let param = {
							url: row.FilePath,
							title: row.FileName,
						}
						that.SendMessage('showPopup', param);
						setTimeout(() => { // 做一下节流操作
							that.throttledOpen = false;
						}, 3000)
					}
				},

				// 向外部通讯
				SendMessage(Text, data) { // 向外部发送

					let Obj = {
						action: Text,
						param: {
							url: '',
							title: '',
						},
					}

					if (Text == 'showPopup') { // 如果是作业指导书，将地址传出去
						Obj['param']['url'] = data.url;
						Obj['param']['title'] = data.title;
					} else if (Text == 'ToReviewPageInfo') { // 不合格评审
						Obj['param']['BadReviewID'] = data.BadReviewID;
					} else if (Text == 'baseScreen') { // 筛选下拉
						Obj['param'] = data
					}
					console.log(JSON.stringify(Obj))

					uni.postMessage({
						data: Obj
					});
				},
				// 外部调用内部方法
				GetBtnPermission(data) {
					console.log(JSON.parse(data))
					this.BtnApprove = JSON.parse(data);
				},
				ApproveBack(str) {
					let that = this;
					let Type = that.BtnApprove.some(item => {
						return item.MenuName == str
					})

					return Type;
				},
				GetDeviceName(val) { // 从外部获取选中协议的 协议类型 和 设备类型
					let data = JSON.parse(val)
					this.DeviceInfo.Communication = data.Communication; // 协议类型
					if (data.Communication == 'HID') {
						this.DeviceInfo.ShowDeviceType = false;
					} else {
						this.DeviceInfo.ShowDeviceType = true;
					};

					this.DeviceInfo.DeviceModel = data.DeviceName; // 设备类型
				},
				SetServiceIP(IP) { // 从外部获取账套IP地址
					var that = this
					let data = JSON.parse(IP);
					APP.serverIP(data.serverIP);
					APP.IPAgreement(data.IPAgreement);
					setTimeout(() => {
						that.getListFun(0)
						that.getListFun(1)
						that.getListFun(2)
						// 获取一下主表检验结果列表
						vm.GetMainResultList()
					}, 300)
				},
				GetUserInfo(data) { // 从外部获取获取用户信息
					var that = this;
					console.log(data);
					that.UserInfo = JSON.parse(data);
					APP.getUserInfo(JSON.parse(data));
				},
				GetDocumentInfo(data) { // 外部调用内部方法，渲染界面
					var that = this
					vm.ChoiceTableCell(JSON.parse(data)) //（点击表格行操作）
				},

				CloseBaseScreen() { // 关闭筛选弹窗
					vm.showBaseScreen = false
					vm.FilterList = []
				},
				ChoiceListCell(data) { // 选中筛选项

					if (vm.SelectName == '品号') {
						APP.jqueryAjax('APP_GetCPXXByCPID', {
							ProductID: data.ProductID
						}, function(res) {
							if (res.status == 200) {

								vm.AddFormData = Object.assign(vm.AddFormData, res.data.ds[0]);
							}
						})
					} else {
						vm.AddFormData = Object.assign(vm.AddFormData, data);
					}
					vm.showBaseScreen = false
					vm.FilterList = []
				},
				GetCJQty() { // 来料失焦时，根据来料数量获取抽检数量
					if (vm.AddFormData.BJNum) {
						let pram = {
							ProductID: vm.AddFormData.ProductID,
							BJNum: vm.AddFormData.BJNum,
						}
						// console.log(JSON.stringify(pram))

						APP.jqueryAjax('APP_selectCJSL', pram, function(res) {
							if (res.data.ds.length && res.data.ds[0].status == 200) {
								vm.AddFormData.CJQty = res.data.ds[0]['SizeNum']
							} else if (res.data.ds.length && res.data.ds[0].status == 500) {
								vant.Toast(res.data.ds[0].msg)
								vm.AddFormData.BJNum = ''
								vm.AddFormData.CJQty = ''
							} else {
								vant.Toast('接口异常，请重试')
							}
							// console.log(JSON.stringify(res))
						})
					} else {
						vm.AddFormData.CJQty = ''
					}
				},
				AddInspectionBtn() { // 新增 未检验单据，打开 生成单据信息弹窗
					vm.AddInspection = true
				},
				CloseAddPopup() { // 关闭 新增弹窗
					vm.AddInspection = false

					// 清空表单数据
					Object.keys(vm.AddFormData).forEach((key) => {
						vm.AddFormData[key] = '';
					})
					// 还原校验状态
					Object.keys(vm.Rule).forEach((key) => {
						vm.Rule[key] = false;
					})
				},
				RefreshTables() { // 刷新列表数据
					// 获取Tabs下 表格数据
					vm.getListFun(0)
					vm.getListFun(1)
					vm.getListFun(2)
				},
				ChangePageIndex(data) { // 修改 未检验 页码
					var that = this;
					clearTimeout(that.PageIndexTimer)

					that.PageIndexTimer = setTimeout(() => {
						vm.getListFun(data)
					}, 400)
				},
				OpenMainBox() { // 打开主表弹窗
					vm.showMainBox = true
					// 给左侧主表弹窗 顶部 加 安全高度
					setTimeout(() => {
						$('.FormBox').css({
							'padding-top': vm.immersed + 'px'
						})
					}, 300)
				},
				ChoiceMainResult(data) { // 修改主表检验结果
					// 点击 cell 后 需要手动修改值，不然无法修改值
					vm.originData.mainData.Result = String(data.ID)
					vm.originData.mainData.Result1 = data.NAME

					vm.ChangeResultPopup = false
				},
				OpenListPopup() { // 选中打开单据列表
					$('li').click(function() {
						$('.button').removeClass('active')
						$('.icons').removeClass('open')
					})

					vm.showListBox = true
					// 获取Tabs下 表格数据
					vm.getListFun(0)
					vm.getListFun(1)
					vm.getListFun(2)

				},
				OpenControl() { // 切换设备

					this.SendMessage('openDeviceControl')

				},
				getPageData() {
					var that = this;
					var headerTitles = that.originData.FQCDetail;
					//获取标题头递归层级
					var headerLevel = that.getHeaderTitlesLevel(headerTitles, 0, 0);
					that.headerLevel = headerLevel;
					var allCellData = [];
					//第一行第一列，标题样品名称
					allCellData.push({
						"r": 0,
						"c": 0,
						"v": {
							"ct": { //单元格值格式
								"fa": "General", //格式名称为自动格式
								"t": "n" //格式类型为数字类型
							},
							"v": '样品名称', //内容的原始值为 233
							"m": '样品名称', //内容的显示值为 233
							// "bg": "#eeeff1", //背景为 "#eeeff1"
							"ff": 1, // 字体为 "Arial"
							"fc": "#333", //字体颜色为 "#333"
							"bl": 1, //字体加粗
							"fs": 9, //字体大小为 9px
							"ht": 0, //水平居中
							"vt": 0, //垂直居中
							"tb": 2, //文本自动换行
							"mc": { //合并单元格必备属性
								"r": 0, //主单元格的行号
								"c": 0, //主单元格的列号
								"rs": headerLevel + 1, //合并单元格占的行数
								"cs": 1 //合并单元格占的列数
							}
						}
					});
					//1、第一行后续几列，按重点层次区分,标题行
					that.getTitleHeader(headerTitles, 0, 0, allCellData, 0);
					//2、确认表格列数，及行数
					var colNums = (headerTitles.filter((item) => {
						return item.Type == 1
					})).length * 3 + (headerTitles.filter((item) => {
						return item.Type == 2
					})).length * 2 + 1;
					var rowNums = headerLevel + 1 + that.originData.inspections.length;
					//样品数检验结果
					allCellData.push({
						"r": 0,
						"c": colNums,
						"v": {
							"ct": { //单元格值格式
								"fa": "General", //格式名称为自动格式
								"t": "n" //格式类型为数字类型
							},
							"v": '检验结果', //内容的原始值为 233
							"m": '检验结果', //内容的显示值为 233
							// "bg": "#eeeff1", //背景为 "#eeeff1"
							"ff": 1, // 字体为 "Arial"
							"fc": "#333", //字体颜色为 "#333"
							"bl": 1, //字体加粗
							"fs": 9, //字体大小为 9px
							"ht": 0, //水平居中
							"vt": 0, //垂直居中
							"tb": 2, //文本自动换行
							"mc": { //合并单元格必备属性
								"r": 0, //主单元格的行号
								"c": colNums, //主单元格的列号
								"rs": headerLevel + 1, //合并单元格占的行数
								"cs": 1 //合并单元格占的列数
							}
						}
					});
					// 增加备注
					allCellData.push({
						"r": 0,
						"c": colNums + 1,
						"v": {
							"ct": { //单元格值格式
								"fa": "General", //格式名称为自动格式
								"t": "n" //格式类型为数字类型
							},
							"v": '备注', //内容的原始值为 233
							"m": '备注', //内容的显示值为 233
							// "bg": "#eeeff1", //背景为 "#eeeff1"
							"ff": 1, // 字体为 "Arial"
							"fc": "#333", //字体颜色为 "#333"
							"bl": 1, //字体加粗
							"fs": 9, //字体大小为 9px
							"ht": 0, //水平居中
							"vt": 0, //垂直居中
							"tb": 2, //文本自动换行
							"mc": { //合并单元格必备属性
								"r": 0, //主单元格的行号
								"c": colNums + 1, //主单元格的列号
								"rs": headerLevel + 1, //合并单元格占的行数
								"cs": 1 //合并单元格占的列数
							}
						}
					});
					// console.log(colNums + 1)
					// 设置备注的索引
					that.RemarkIndex.c = colNums + 1;
					that.RemarkIndex.r = headerLevel;
					var dataVerfications = {}
					//样品行数
					//that.getValueData();
					for (var i = 0; i < that.originData.inspections.length; i++) {
						var v = {
							"r": headerLevel + 1 + i,
							"c": 0,
							"v": {
								"v": that.originData.inspections[i].name,
								"m": that.originData.inspections[i].name,
								// "bg": "#eeeff1", //背景为 "#eeeff1"
								"ff": 1, // 字体为 "Arial"
								"fc": "#333", //字体颜色为 "#333"
								"bl": 0, //字体加粗
								"fs": 9, //字体大小为 9px
								"ht": 0, //水平居中
								"vt": 0, //垂直居中
								"tb": 2, //文本自动换行
							}
						}
						allCellData.push(v);
						dataVerfications[(headerLevel + 1 + i) + '_' + colNums] = {
							type: 'checkbox',
							type2: null,
							value1: '合格',
							value2: '不合格',
							checked: (that.originData.inspections[i].result == '1' ? true : false)
						}
						allCellData.push({
							"r": headerLevel + 1 + i,
							"c": colNums,
							"v": {
								"v": that.originData.inspections[i].result == "1" ? "合格" :
								"不合格", //内容的原始值为 233
								"m": that.originData.inspections[i].result == "1" ? "合格" :
								"不合格", //内容的显示值为 233
								// "bg": "#eeeff1", //背景为 "#eeeff1"
								"ff": 1, // 字体为 "Arial"
								"fc": (that.originData.inspections[i].result == '1' ? "#07d348" :
									"#f00"),
								"bl": 0, //字体加粗
								"fs": 9, //字体大小为 9px
								"ht": 1, //水平居中
								"vt": 0, //垂直居中
								"tb": 2, //文本自动换行
							}
						});
						// 给备注单元格赋值
						allCellData.push({
							"r": headerLevel + 1 + i,
							"c": colNums + 1,
							"v": {
								"v": that.originData.inspections[i].FRemarks, //内容的原始值为 233
								"m": that.originData.inspections[i].FRemarks, //内容的显示值为 233
								// "bg": "#eeeff1", //背景为 "#eeeff1"
								"ff": 1, // 字体为 "Arial"
								"fc": "#333", //字体颜色为 "#333"
								"bl": 0, //字体加粗
								"fs": 9, //字体大小为 9px
								"ht": 0, //水平居中
								"vt": 0, //垂直居中
								"tb": 2, //文本自动换行
							}
						});
						var type1Details = that.originData.FQCDetail.filter((item) => {
							return item.Type == 1
						});
						for (var j = 0; j < type1Details.length; j++) {
							var v1 = {
								"r": headerLevel + 1 + i,
								"c": type1Details[j].c,
								"v": {
									"v": type1Details[j].maxNum, //内容的原始值为 233
									"m": type1Details[j].maxNum, //内容的显示值为 233
									// "bg": "#eeeff1", //背景为 "#eeeff1"
									"ff": 1, // 字体为 "Arial"
									"fc": "#333", //字体颜色为 "#333"
									"bl": 0, //字体加粗
									"fs": 9, //字体大小为 9px
									"ht": 0, //水平居中
									"vt": 0, //垂直居中
									"tb": 2, //文本自动换行
								}
							}
							allCellData.push(v1);
							var v2 = {
								"r": headerLevel + 1 + i,
								"c": type1Details[j].c + 1,
								"v": {
									"v": type1Details[j].minNum, //内容的原始值为 233
									"m": type1Details[j].minNum, //内容的显示值为 233
									// "bg": "#eeeff1", //背景为 "#eeeff1"
									"ff": 1, // 字体为 "Arial"
									"fc": "#333", //字体颜色为 "#333"
									"bl": 0, //字体加粗
									"fs": 9, //字体大小为 9px
									"ht": 0, //水平居中
									"vt": 0, //垂直居中
									"tb": 2, //文本自动换行
								}
							}
							allCellData.push(v2);
							//实测值，后台传过来的
							var actualValue = that.originData.inspections[i].FQCItems.filter((item) => {
								return item.FQCItemID == type1Details[j].ItemID
							});
							actualValue[0].r = headerLevel + 1 + i;
							actualValue[0].c = type1Details[j].c + 2;
							actualValue[0].minNum = type1Details[j].minNum;
							actualValue[0].maxNum = type1Details[j].maxNum;
							var fc = "#333";
							if ($.isNumeric(actualValue[0].minNum) && $.isNumeric(actualValue[0].maxNum)) {
								if (parseFloat(actualValue[0].value) >= parseFloat(actualValue[0].minNum) &&
									parseFloat(actualValue[0].value) <= parseFloat(actualValue[0].maxNum)
								) {
									fc = "#07d348";
								} else {
									fc = "#f00";
								}
							}
							var v3 = {
								"r": headerLevel + 1 + i,
								"c": type1Details[j].c + 2,
								"v": {
									"v": actualValue[0].value, //内容的原始值为 233
									"m": actualValue[0].value, //内容的显示值为 233
									// "bg": "#eeeff1", //背景为 "#eeeff1"
									"ff": 1, // 字体为 "Arial"
									"fc": fc, //字体颜色为 "#333"
									"bl": 0, //字体加粗
									"fs": 9, //字体大小为 9px
									"ht": 0, //水平居中
									"vt": 0, //垂直居中
									"tb": 2, //文本自动换行
								}
							}
							allCellData.push(v3);
							that.editCells.push(v3);
						}
						var type2Details = that.originData.FQCDetail.filter((item) => {
							return item.Type == 2
						});
						for (var j = 0; j < type2Details.length; j++) {
							var v1 = {
								"r": headerLevel + 1 + i,
								"c": type2Details[j].c,
								"v": {
									"v": type2Details[j].JYBZ, //内容的原始值为 233
									"m": type2Details[j].JYBZ, //内容的显示值为 233
									// "bg": "#eeeff1", //背景为 "#eeeff1"
									"ff": 1, // 字体为 "Arial"
									"fc": "#333", //字体颜色为 "#333"
									"bl": 0, //字体加粗
									"fs": 9, //字体大小为 9px
									"ht": 0, //水平居中
									"vt": 0, //垂直居中
									"tb": 2, //文本自动换行
								}
							}
							allCellData.push(v1);
							var actualValue = that.originData.inspections[i].FQCItems.filter((item) => {
								return item.FQCItemID == type2Details[j].ItemID
							});
							actualValue[0].r = headerLevel + 1 + i;
							actualValue[0].c = type2Details[j].c + 1;
							// if (!actualValue[0].value) {
							// 	actualValue[0].value = type2Details[j].JYBZ;
							// }
							let fc = "#333";
							if (actualValue[j].value) {
								if (actualValue[j].value.toLowerCase() == "ng") {
									fc = "#f00";
								} else if (actualValue[j].value.toLowerCase() == "ok") {
									fc = "#07d348";
								}
							}
							var v3 = {
								"r": headerLevel + 1 + i,
								"c": type2Details[j].c + 1,
								"v": {
									"v": actualValue[0].value, //内容的原始值为 233
									"m": actualValue[0].value, //内容的显示值为 233
									// "bg": "#eeeff1", //背景为 "#eeeff1"
									"ff": 1, // 字体为 "Arial"
									"fc": fc, //字体颜色为 "#333"
									"bl": 0, //字体加粗
									"fs": 9, //字体大小为 9px
									"ht": 0, //水平居中
									"vt": 0, //垂直居中
									"tb": 2, //文本自动换行
								}
							}
							allCellData.push(v3);
							that.editCells.push(v3);
						}
					}
					that.ExcleInit(rowNums, colNums, allCellData, dataVerfications);
				},
				getHeaderTitlesLevel(originData, parentID, originLevel) {
					var that = this;
					var maxLevel = originLevel;
					for (var i = 0; i < originData.length; i++) {
						if (originData[i].UpID == parentID) {
							var curLevel = that.getHeaderTitlesLevel(originData, originData[i].ItemID,
								originLevel +
								1);
							if (curLevel > maxLevel) {
								maxLevel = curLevel;
							}
						}
					}
					return maxLevel;
				},
				getTitleHeader(originData, parentID, originLevel, allCellData, originCNum) {
					var that = this;
					var cNum = originCNum;
					for (var i = 0; i < originData.length; i++) {
						if (originData[i].UpID == parentID) {
							if (originData[i].Type == 0) {
								var cSplitNum = that.getSplitNum(originData, originData[i].ItemID);
								var cell = {
									"r": originLevel,
									"c": cNum + 1,
									"v": {
										"ct": { //单元格值格式
											"fa": "General", //格式名称为自动格式
											"t": "n" //格式类型为数字类型
										},
										"v": originData[i].ItemName, //内容的原始值为 233
										"m": originData[i].ItemName, //内容的显示值为 233
										// "bg": "#eeeff1", //背景为 "#eeeff1"
										"ff": 1, // 字体为 "Arial"
										"fc": "#333", //字体颜色为 "#333"
										"bl": 1, //字体加粗
										"fs": 9, //字体大小为 9px
										"ht": 0, //水平居中
										"vt": 0, //垂直居中
										"tb": 2, //文本自动换行
										"mc": { //合并单元格必备属性
											"r": originLevel, //主单元格的行号
											"c": cNum + 1, //主单元格的列号
											"rs": 1, //合并单元格占的行数
											"cs": cSplitNum //合并单元格占的列数
										}
									}
								}
								allCellData.push(cell);
								that.getTitleHeader(originData, originData[i].ItemID, originLevel + 1,
									allCellData,
									cNum);
								cNum = cNum + cSplitNum;
							} else if (originData[i].Type == 1) {
								originData[i].c = cNum + 1;
								var cell = {
									"r": originLevel,
									"c": cNum + 1,
									"v": {
										"ct": { //单元格值格式
											"fa": "General", //格式名称为自动格式
											"t": "n" //格式类型为数字类型
										},
										"v": originData[i].ItemName, //内容的原始值为 233
										"m": originData[i].ItemName, //内容的显示值为 233
										// "bg": "#eeeff1", //背景为 "#eeeff1"
										"ff": 1, // 字体为 "Arial"
										"fc": "#333", //字体颜色为 "#333"
										"bl": 1, //字体加粗
										"fs": 9, //字体大小为 9px
										"ht": 0, //水平居中
										"vt": 0, //垂直居中
										"tb": 2, //文本自动换行
										"mc": { //合并单元格必备属性
											"r": originLevel, //主单元格的行号
											"c": cNum + 1, //主单元格的列号
											"rs": 1, //合并单元格占的行数
											"cs": 3 //合并单元格占的列数
										}
									}
								}
								allCellData.push(cell);

								var cell2 = {
									"r": originLevel + 1,
									"c": cNum + 1,
									"v": {
										"ct": { //单元格值格式
											"fa": "General", //格式名称为自动格式
											"t": "n" //格式类型为数字类型
										},
										"v": '上极限', //内容的原始值为 233
										"m": '上极限', //内容的显示值为 233
										// "bg": "#eeeff1", //背景为 "#eeeff1"
										"ff": 1, // 字体为 "Arial"
										"fc": "#333", //字体颜色为 "#333"
										"bl": 1, //字体加粗
										"fs": 9, //字体大小为 9px
										"ht": 0, //水平居中
										"vt": 0, //垂直居中
										"tb": 2, //文本自动换行
										"mc": { //合并单元格必备属性
											"r": originLevel + 1, //主单元格的行号
											"c": cNum + 1, //主单元格的列号
											"rs": 1, //合并单元格占的行数
											"cs": 1 //合并单元格占的列数
										}
									}
								}

								var cell3 = {
									"r": originLevel + 1,
									"c": cNum + 2,
									"v": {
										"ct": { //单元格值格式
											"fa": "General", //格式名称为自动格式
											"t": "n" //格式类型为数字类型
										},
										"v": '下极限', //内容的原始值为 233
										"m": '下极限', //内容的显示值为 233
										// "bg": "#eeeff1", //背景为 "#eeeff1"
										"ff": 1, // 字体为 "Arial"
										"fc": "#333", //字体颜色为 "#333"
										"bl": 1, //字体加粗
										"fs": 9, //字体大小为 9px
										"ht": 0, //水平居中
										"vt": 0, //垂直居中
										"tb": 2, //文本自动换行
										"mc": { //合并单元格必备属性
											"r": originLevel + 1, //主单元格的行号
											"c": cNum + 2, //主单元格的列号
											"rs": 1, //合并单元格占的行数
											"cs": 1 //合并单元格占的列数
										}
									}
								}

								var cell4 = {
									"r": originLevel + 1,
									"c": cNum + 3,
									"v": {
										"ct": { //单元格值格式
											"fa": "General", //格式名称为自动格式
											"t": "n" //格式类型为数字类型
										},
										"v": '实测值', //内容的原始值为 233
										"m": '实测值', //内容的显示值为 233
										// "bg": "#eeeff1", //背景为 "#eeeff1"
										"ff": 1, // 字体为 "Arial"
										"fc": "#333", //字体颜色为 "#333"
										"bl": 1, //字体加粗
										"fs": 9, //字体大小为 9px
										"ht": 0, //水平居中
										"vt": 0, //垂直居中
										"tb": 2, //文本自动换行
										"mc": { //合并单元格必备属性
											"r": originLevel + 1, //主单元格的行号
											"c": cNum + 3, //主单元格的列号
											"rs": 1, //合并单元格占的行数
											"cs": 1 //合并单元格占的列数
										}
									}
								}
								allCellData.push(cell2);
								allCellData.push(cell3);
								allCellData.push(cell4);
								cNum = cNum + 3;
								//that.getTitleHeader(originData,originData[i].ItemID,originLevel+1,allCellData);
							} else if (originData[i].Type == 2) {
								originData[i].c = cNum + 1;
								var cell = {
									"r": originLevel,
									"c": cNum + 1,
									"v": {
										"ct": { //单元格值格式
											"fa": "General", //格式名称为自动格式
											"t": "n" //格式类型为数字类型
										},
										"v": originData[i].ItemName, //内容的原始值为 233
										"m": originData[i].ItemName, //内容的显示值为 233
										// "bg": "#eeeff1", //背景为 "#eeeff1"
										"ff": 1, // 字体为 "Arial"
										"fc": "#333", //字体颜色为 "#333"
										"bl": 1, //字体加粗
										"fs": 9, //字体大小为 9px
										"ht": 0, //水平居中
										"vt": 0, //垂直居中
										"tb": 2, //文本自动换行
										"mc": { //合并单元格必备属性
											"r": originLevel, //主单元格的行号
											"c": cNum + 1, //主单元格的列号
											"rs": 1, //合并单元格占的行数
											"cs": 2 //合并单元格占的列数
										}
									}
								}

								allCellData.push(cell);

								var cell2 = {
									"r": originLevel + 1,
									"c": cNum + 1,
									"v": {
										"ct": { //单元格值格式
											"fa": "General", //格式名称为自动格式
											"t": "n" //格式类型为数字类型
										},
										"v": '检验标准', //内容的原始值为 233
										"m": '检验标准', //内容的显示值为 233
										// "bg": "#eeeff1", //背景为 "#eeeff1"
										"ff": 1, // 字体为 "Arial"
										"fc": "#333", //字体颜色为 "#333"
										"bl": 1, //字体加粗
										"fs": 9, //字体大小为 9px
										"ht": 0, //水平居中
										"vt": 0, //垂直居中
										"tb": 2, //文本自动换行
										"mc": { //合并单元格必备属性
											"r": originLevel + 1, //主单元格的行号
											"c": cNum + 1, //主单元格的列号
											"rs": 1, //合并单元格占的行数
											"cs": 1 //合并单元格占的列数
										}
									}
								}

								var cell3 = {
									"r": originLevel + 1,
									"c": cNum + 2,
									"v": {
										"ct": { //单元格值格式
											"fa": "General", //格式名称为自动格式
											"t": "n" //格式类型为数字类型
										},
										"v": '实测值', //内容的原始值为 233
										"m": '实测值', //内容的显示值为 233
										// "bg": "#eeeff1", //背景为 "#eeeff1"
										"ff": 1, // 字体为 "Arial"
										"fc": "#333", //字体颜色为 "#333"
										"bl": 1, //字体加粗
										"fs": 9, //字体大小为 9px
										"ht": 0, //水平居中
										"vt": 0, //垂直居中
										"tb": 2, //文本自动换行
										"mc": { //合并单元格必备属性
											"r": originLevel + 1, //主单元格的行号
											"c": cNum + 2, //主单元格的列号
											"rs": 1, //合并单元格占的行数
											"cs": 1 //合并单元格占的列数
										}
									}
								}
								allCellData.push(cell2);
								allCellData.push(cell3);
								cNum = cNum + 2;
								//that.getTitleHeader(originData,originData[i].ItemID,originLevel+1,allCellData);
							}

						}
					}
				},
				getSplitNum(originData, parentID) {
					var that = this;
					var splitNum = 0;
					for (var i = 0; i < originData.length; i++) {
						if (originData[i].UpID == parentID) {
							if (originData[i].Type == 0) {
								var subSplitNum = that.getSplitNum(originData, originData[i].ItemID);
								splitNum = splitNum + subSplitNum;
							} else if (originData[i].Type == 1) {
								splitNum = splitNum + 3;
							} else {
								splitNum = splitNum + 2;
							}
						}
					}
					return splitNum;
				},
				cellToIndex(cell) { // 单元格转换  将 A1 转换成 [0,0]
					return APP.excelAddressToArrayIndex(cell)
				},
				indexToCell(index) { // 将 [0,0] 转换成 A1  [26,0] => AA1
					const column = APP.createCellPos(index[1]); // 将列索引转换为列字母，0对应A，1对应B，以此类推
					const row = index[0] + 1; // 将行索引转换为行数字，加上1是因为单元格标识从1开始
					return column + row;
				},
				setRange(data) { // 父组件调用子组件事件 - data => 父组件传入的值;
					let dataArray = data.split(',');
					// IsWhere => A1 => [0,0]
					// 1、获取选中单元格行列位置
					const Iswhere = vm.cellToIndex(vm.IsWhere);
					let ranged = {
						r: Iswhere[0],
						c: Iswhere[1],
					};
					console.log(JSON.stringify(ranged));
					//考虑到data是由逗号分割的字符串
					if (dataArray.length > 1) {
						//1、某一行 有实测值1、实测值2、实测值3
						//2、点击其中一个实测值 赋值该行的所有实测值
						//获取该行的所有可填实测值
						let AllFilterData = [];
						vm.originData.inspections.forEach(item => {
							let FilterData = item.FQCItems.filter(ReItem => {
								return ReItem.r == ranged.r && ReItem.Benchmark.indexOf(vm.DeviceInfo
									.DeviceModel) != -1;
							});
							if (FilterData.length) {
								AllFilterData.push(FilterData);
							};
						});
						//按行列大小排序
						AllFilterData[0].sort((a, b) => {
							return (a.c - b.c);
						});
						for (let i = 0; i < AllFilterData[0].length; i++) {
							vm.IsWhere = vm.indexToCell([AllFilterData[0][i].r, AllFilterData[0][i].c]);
							let NewData = [
								[{
									"m": dataArray[i], // 显示值
									"v": dataArray[i], // 原始值
									"ht": 0, // 水平对齐 0 居中、1 左、2右	
									"vt": 0, // 垂直对齐 0 中间、1 上、2下
									"tb": 2, // 文本换行 0 截断、1溢出、2 自动换行
								}]
							]
							console.log(JSON.stringify(NewData))
							//点击该行的任意一个单元格也会对该行的所有可填实测值赋值
							vm.ChoiceCell(NewData)
						}
					} else {
						const NewData = [
							[{
								"m": data, // 显示值
								"v": data, // 原始值
								"ht": 0, // 水平对齐 0 居中、1 左、2右	
								"vt": 0, // 垂直对齐 0 中间、1 上、2下
								"tb": 2, // 文本换行 0 截断、1溢出、2 自动换行
							}]
						];
						// 首先判断选中单元格是否需要所属检验工具测量
						// 判断当前项是否为报告类型
						if (vm.ChoiceCellData && vm.ChoiceCellData.hasOwnProperty("IsLaboratory") && vm.ChoiceCellData
							.IsLaboratory) {
							// 直接赋值
							vm.AssignmentFun(NewData, data);
						} else {
							// 外部数据传入--赋值--跳转下一个
							// 2、过滤出填报项列表中
							// 2.1、是否包含该位置单元格，
							// 2.2、如果包含，判断检验工具是否为连接设备
							let AllFilterData = [];
							vm.originData.inspections.forEach(item => {
								let FilterData = item.FQCItems.filter(ReItem => {
									return ReItem.r == ranged.r && ReItem.c == ranged.c && ReItem
										.Benchmark.indexOf(vm.DeviceInfo.DeviceModel) != -1;
								});
								if (FilterData.length) {
									AllFilterData.push(FilterData);
								};
							});
							// 3、如果选中项属于填写数据，且填写设备 Benchmark 为连接设备，则进行赋值操作，并选择下一个，反之，提示错误
							if (AllFilterData.length) {
								vm.ChoiceCell(NewData)
							} else {
								vant.Toast('请检查测量设备是否一致，或是否选中正确单元格')
							}
						}
					}
				},
				GetDeviceStatus(data) { // 获取设备连接状态
					vm.deviceStatus = JSON.parse(data);
				},
				NumberMapBack(data) {
					if (data) {
						return data.replace(/。/, '.', 1);
					}
					return '';
				},
				AssignmentFun(data, value) { // 赋值操作
					// vm.editKeyword = data[0][0]['v']
					$('#autoInput').val(data[0][0]['v'])
					// 修改界面上显示的数值
					luckysheet.setRangeValue(data, {
						range: vm.IsWhere + ':' + vm.IsWhere
					})
					// 拿到回传的单元格位置后，转换格式： A1 => [0,0]
					var CellWhere = vm.cellToIndex(vm.IsWhere)
					var TheIndex = null
					// 将单元格位置信息与数据进行匹配，替换所在单元格的value值
					vm.originData.inspections.forEach((item, index) => {
						item.FQCItems.forEach(ReItem => {
							if (ReItem.r == CellWhere[0] && ReItem.c == CellWhere[1]) {
								TheIndex = index
								ReItem.value = value
								// 如果该单元格数据是有 上下限, 1 => 合格, 2 => 不合格
								if (ReItem.minNum && ReItem.maxNum) {
									let keyValue = +vm.NumberMapBack($('#autoInput').val()) || 0;
									if (+ReItem.maxNum >= keyValue && keyValue >= +ReItem.minNum) {
										ReItem.result = 1
									} else {
										ReItem.result = 2
									}
								} else {
									if (ReItem.value.toLowerCase() === 'ok') {
										ReItem.result = 1
									} else if (ReItem.value.toLowerCase() === 'ng') {
										ReItem.result = 2;
									} else {
										ReItem.result = -1;
									}
									// 检验标准的实测值默认返回1
									// 查找该实测值的检验标准
									// var FindData = vm.originData.FQCDetail.find(item => {
									// 	return item.c == ReItem.c - 1
									// }).JYBZ
									// // 如果检验标准与实测值相同,则result为1
									// if (FindData == ReItem.value) {
									// 	ReItem.result = 1
									// } else {
									// 	ReItem.result = 2
									// }
									// ReItem.result = 1
								}
							}
							// if (ReItem.minNum && ReItem.maxNum) {} else {
							// 	// 检验标准的实测值默认返回1
							// 	ReItem.result = 1
							// }
						})
					})
					// 根据当前样品的result是否为true，改变检验结果
					vm.originData.inspections.forEach((item, index) => {
						if (TheIndex == index) {
							let HasNotResult = item.FQCItems.some(ReItem => {
								return ReItem.result == 2
							})
							if (HasNotResult) {
								item.result = 2
							} else {
								item.result = 1
							}
						}
					})
					// 更改行的检验结果
					vm.ChangeRowResult(CellWhere[0], TheIndex)
				},
				ChangeRowResult(CellWhere, TheIndex) { // 更改行的检验结果

					const NewData = [
						[{
							"m": vm.originData.inspections[TheIndex].result == 1 ? '合格' : '不合格', // 显示值
							"v": vm.originData.inspections[TheIndex].result == 1 ? '合格' : '不合格', // 原始值
							"ht": 1, // 水平对齐 0 居中、1 左、2右	
							"vt": 0, // 垂直对齐 0 中间、1 上、2下
							"tb": 2, // 文本换行 0 截断、1溢出、2 自动换行 
							"fc": (vm.originData.inspections[TheIndex].result == 1 ? "#07d348" : "#f00")
						}]
					]

					// 获取检验结果列
					var MaxColumn = countMax(vm.originData.inspections[TheIndex].FQCItems, 'c')

					// console.log(JSON.stringify(MaxColumn))
					//回写单元格
					var IsWhere = vm.indexToCell([CellWhere, MaxColumn + 1])
					luckysheet.setRangeValue(NewData, {
						range: IsWhere + ':' + IsWhere
					});

					// 计算合格率
					vm.QualifiedRate = BackRercentageData(vm.originData.inspections, 'result', 1)

					luckysheet.setDataVerification({
						type: 'checkbox',
						type2: null,
						value1: '合格',
						value2: '不合格',
						checked: vm.originData.inspections[TheIndex].result == 1 ? true : false
					}, {
						range: IsWhere
					});
				},
				ChoiceCell(data) { // 赋值完选择下一个
					// 赋值
					vm.AssignmentFun(data, data[0][0]['v'])

					/**
					 *  AllFQCItems 			符合检验设备的总数组  
					 *  CellWhere 			选中项单元格所在位置  
					 *  vm.isProductPriority  横纵向， 横向 true，纵向 false
					 */
					// 获取选中位置 将 A1 类型转化为 [0,0]
					let CellWhere = vm.cellToIndex(vm.IsWhere)
					let AllFQCItems = [] // 接收一个总的数组，按顺序操作
					// 如果是横向赋值
					if (vm.isProductPriority) {
						// 横向 => 按样品顺序push
						vm.originData.inspections.forEach((item) => {
							// AllFQCItems.push(...item.FQCItems)
							let Arr = []
							item.FQCItems.forEach(ReItem => {

								if (ReItem.Benchmark.indexOf(vm.DeviceInfo.DeviceModel) != -1) {
									Arr.push(ReItem)
								}
							})
							AllFQCItems.push(...Arr)

						})

					} else {
						// 纵向 => 按 将每一个样品从头到尾的顺序，一起push
						let AllArr = []
						vm.originData.inspections.forEach((item, index) => {

							let Arr = []
							item.FQCItems.forEach(ReItem => {

								if (ReItem.Benchmark.indexOf(vm.DeviceInfo.DeviceModel) != -1) {
									Arr.push(ReItem)
								}
							})
							AllArr.push(Arr)
						})

						let List = []
						if (AllArr.length) {
							for (let i = 0; i < AllArr[0].length; i++) {

								for (let j = 0; j < AllArr.length; j++) {
									AllFQCItems.push(AllArr[j][i])

								}
							}
						}
					}


					let r = CellWhere[0]
					let c = CellWhere[1]

					let RIndex = 0 // 行
					let CIndex = 0 // 列

					let TheIndex = 0
					AllFQCItems.forEach((item, index) => {
						if (item.r == r && item.c == c) {
							TheIndex = index
						}
					})
					// 从符合条件的数组中，过滤掉 被赋值项本身及之前的数据；用filter是为了防止原数组被修改
					let NewAllFQCItems = AllFQCItems.filter((item, index) => {
						return index > TheIndex
					})
					// 过滤完后，还有数据，则跳下一个；反之弹出提醒，可录入完毕
					if (NewAllFQCItems.length) {
						// 选中
						let IsWhere = vm.indexToCell([NewAllFQCItems[0].r, NewAllFQCItems[0].c])
						luckysheet.setRangeShow(IsWhere + ':' + IsWhere);
						vm.IsWhere = IsWhere

					} else {
						console.log('结束')
						vm.showEditWindow = false;
					}

				},
				GoBack() {
					setTimeout(() => {
						// uni.navigateBack()
						let Obj = {
							action: 'GoBack',
							param: {
								url: '',
								title: '',
							},
						}
						// console.log(JSON.stringify(Obj))

						uni.postMessage({
							data: Obj
						});
					}, 30)
				},
				ExcleInit(rowNums, colNums, cellData, dataVerfications) {
					var that = this
					var options = {
						container: 'luckysheet', //luckysheet is the container id
						title: 'Luckysheet Demo', // 设定表格名称
						lang: 'zh', // 设定表格语言
						showtoolbar: false,
						showinfobar: false,
						showsheetbar: false,
						sheetFormulaBar: false,
						showstatisticBar: true, // 缩放按钮
						showcolumnbar: false,
						enableAddRow: false,
						enableAddBackTop: false,
						keyboardenable: false, // 禁止键盘弹起选中单元格
						editable: false, // 设置为只读模式
						rowHeaderWidth: 0,
						columnHeaderHeight: 0,
						rowTitleCellRenderAfter: false,
						columnTitleCellRenderAfter: false,
						data: luckysheetConfig.getOptionsData(rowNums, colNums, cellData, dataVerfications),
						hook: {
							rangeSelect(sheet, range) { // 框选或者设置选区后触发,(点击单元格)
								luckysheetConfig.rangeSelect(sheet, range, rowNums, colNums);
							},
							cellEditBefore: (range) => { // 双击单元格
								luckysheetConfig.cellEditBefore(range, rowNums, colNums);
							},
							rowTitleCellRenderBefore: function(rowNum, position, ctx) {
								return false;
							},
							columnTitleCellRenderBefore: function() {
								return false;
							},
							cellMousedownBefore(cell, position) {
								vm.IsWhere = vm.indexToCell([position.r, position.c])
								luckysheet.setRangeShow(vm.IsWhere + ':' + vm.IsWhere);
								return false;
							},
							cellUpdated(r, c, oldValue, newValue, isRefresh) {
								debugger
								luckysheetConfig.cellUpdated(r, c, oldValue, newValue, isRefresh);
							}
						}
					}
					luckysheet.create(options)


					setTimeout(() => {
						/**
						 * 将FQCItems中的数据手动排序，处理过后的数据，顺序有点问题
						 */
						vm.originData.inspections.forEach(item => {
							item.FQCItems.sort(function(a, b) {
								return a.c - b.c;
							})
						})
						/** 获取根据来料数量，允许的不合格数范围
						 * FinalInspectionID  	主键ID
						 * BJNum	来料数量
						 */
						let OBJ = {
							FinalInspectionID: vm.originData.mainData.FinalInspectionID,
							BJNum: vm.originData.mainData.BJNum,
						}
						vm.GetAllowErrors(OBJ)
						// 根据样品检验结果，更改值
						// vm.originData.inspections.forEach((item, index) => {

						// 	vm.ChangeRowResult(item.FQCItems[0].r, index)
						// })
						// 将选中框，调整到 第一个可填位置
						if (vm.originData.inspections.length && vm.originData.inspections[0].FQCItems
							.length && vm
							.originData.inspections[0].FQCItems[0].c && vm.originData.inspections[0].FQCItems[
								0].r) {

							let IsWhere = vm.indexToCell([
								vm.originData.inspections[0].FQCItems[0].r,
								vm.originData.inspections[0].FQCItems[0].c
							])
							// 选中
							vm.IsWhere = IsWhere
							luckysheet.setRangeShow(IsWhere + ':' + IsWhere);
						}
					}, 500)

				},
				tableData_Report_change(index) { // 报告列表切换
					let ReportData = vm.tableData_Report[index];
					Object.assign(vm.popup_ReportData, ReportData);
				},
				ViewReportInfoBtn() { // 预览报告按钮
					let index = vm.tableData_Report_radio;
					let ReportData = vm.tableData_Report[index];
					basicConfig.ViewPopupInfoByDevice(vm.DeviceInfo.NeedDevice, JSON.stringify(ReportData));

				},
				SubmitViewReportInfoBtn() { // 确认预览报告按钮
					vm.submitRowInfo();
				},
				SendReportBtn() { // 测试发送报告数据
					basicConfig.GetPopupInfoByDevice(vm.DeviceInfo.NeedDevice);
				},
				submitRowInfo() { // 报告类型弹层确认按钮事件
					basicConfig.SubmitPopupInfoByDevice(vm.DeviceInfo.NeedDevice);
				},
				submitKeyword() { // 点击输入框右侧确认按钮
					basicConfig.submitKeyword();
				},
				BlurSearch() { // 赋值输入框失焦
					vm.InputFocus = 'none';

					setTimeout(() => {

						// 隐藏输入框
						vm.showEditWindow = false;
					}, 30)
				},
				closeJYResult() {
					const NewData = [
						[{
							"m": vm.isJYResult, // 显示值
							"v": vm.isJYResult, // 原始值
							"ht": 1, // 水平对齐 0 居中、1 左、2右	
							"vt": 0, // 垂直对齐 0 中间、1 上、2下
							"tb": 2, // 文本换行 0 截断、1溢出、2 自动换行 
							"fc": (vm.isJYResult == '合格' ? "#07d348" : "#f00")
						}]
					]
					//回写单元格
					var IsWhere = vm.indexToCell([vm.editRange[0].row[0], vm.editRange[0].column[0]])
					luckysheet.setRangeValue(NewData, {
						range: IsWhere + ':' + IsWhere
					});
					//更新主表头数据
					var ypIndex = vm.editRange[0].row[0] - 1 - vm.headerLevel;
					vm.originData.inspections[ypIndex].result = (vm.isJYResult == '合格' ? 1 : 2);

					// 计算合格率
					vm.QualifiedRate = BackRercentageData(vm.originData.inspections, 'result', 1)


					if (vm.isJYResult == "合格") {
						luckysheet.setDataVerification({
							type: 'checkbox',
							type2: null,
							value1: '合格',
							value2: '不合格',
							checked: true
						});
					} else {
						luckysheet.setDataVerification({
							type: 'checkbox',
							type2: null,
							value1: '合格',
							value2: '不合格',
							checked: false
						});
					}
					luckysheet.setRangeShow('A1:A1', {
						show: false
					});
				},
				onClickLeft() {
					vant.Dialog.confirm({
						title: '提示',
						message: '是否确认退出？',
					}).then(() => {
						vm.GoBack()
					}).catch(() => {

					});
				}
			}
		})

		// 监听屏幕旋转
		window.addEventListener("orientationchange", function() {

			if (Math.abs(window.orientation) === 90) {
				// console.log('这是竖屏')
			}
			if (Math.abs(window.orientation) === 0) {
				// console.log('这是横屏')
			}
		}, false);


		/** 根据选中的单元格位置，获取单元格的信息 用于'originData.inspections'
		 * @param arr  搜寻的原数组， this.originData.inspections
		 * @param data 选中的坐标位置，如 {r:0,c:0}
		 */
		function GetChoiceCellData(arr, data) {
			var that = this
			for (var i = 0; i < arr.length; i++) {
				for (var j = 0; j < arr[i].FQCItems.length; j++) {

					if (arr[i].FQCItems[j].r == data.r &&
						arr[i].FQCItems[j].c == data.c) {

						return arr[i].FQCItems[j]
					}
				}
			}
		}

		/**
		 * 根据选中的单元格位置，获取单元格的信息 用于'originData.inspections'
		 * @param {Array} arr  搜寻的原数组， this.originData.inspections
		 * @param {Object} data 选中的坐标位置，如 {r:0, c:0}
		 * @return {Object|undefined} 找到的单元格对象，如果没有找到则返回 undefined
		 */
		function GetChoiceCellData(arr, data) {
			var rowCount = arr.length;
			var foundItem = undefined;

			// 使用标志变量来跟踪是否找到匹配项，以便可以早期退出
			var found = false;

			for (var i = 0; i < rowCount && !found; i++) {
				var fqcItems = arr[i].FQCItems;
				var itemCount = fqcItems.length;

				for (var j = 0; j < itemCount && !found; j++) {
					if (fqcItems[j].r === data.r && fqcItems[j].c === data.c) {
						foundItem = fqcItems[j];
						found = true; // 设置标志为 true，以便外层循环可以早期退出
					}
				}
			}

			return foundItem;
		}

		/**
		 * 求百分比函数
		 * 求该字段在数组中所占百分比
		 * @param arr 		对象数组
		 * @param attribute 字段名称
		 * @param value 	比较的值
		 * @return {string} 返回一个字符串（'50%'）
		 */
		function BackRercentageData(arr, attribute, value) {

			let MeetNums = arr.filter(item => {
				/* 当Fresult是无值的情况下，默认为1 */
				let data = item[attribute];
				if (APP.isEmpty(item[attribute])) {
					data = 1;
				}
				return data == value
			}).length

			let num = parseFloat(MeetNums);
			let total = parseFloat(arr.length);

			if (isNaN(num) || isNaN(total)) {
				return "-";
			}
			return total <= 0 ? "0%" : Math.round((num / total) * 10000) / 100.0 + "%";
		}

		/**
		 * 求百分比
		 * @param  num 		当前数
		 * @param  total 	总数
		 * @return {string} 返回一个字符串（'50%'）
		 */
		function getPercent(num, total) {
			num = parseFloat(num);
			total = parseFloat(total);
			if (isNaN(num) || isNaN(total)) {
				return "-";
			}
			return total <= 0 ? "0%" : Math.round((num / total) * 10000) / 100.0 + "%";
		}

		/** 求对象数组中某一属性最大值
		 * @param arr 对象数组
		 * @param key 对比的属性
		 */
		function countMax(arr, key) {
			return Math.max.apply(Math, arr.map(item => {
				return item[key]
			}))
		}
	</script>

</html>